{% extends 'base.html' %}
{% block title %}个人主页{% endblock %}
{% block content %}
    {% for message in get_flashed_messages() %}
        <span style="color: red">{{ message }}</span>
    {% endfor %}

    <table>
        <tr valign="top">
            <td><img src="{{ user.avatar(128) }}" alt="头像"/></td>
            <td>
                <h1>用户：{{ user.nickname }}</h1>
                {% if user.about_me %}
                    <p>{{ user.about_me }}</p>
                {% endif %}
                {% if user.last_seen %}
                    <p><i>最后登录时间：{{ user.last_seen }}</i></p>
                {% endif %}
                <p>{{ user.followers.count() }} 关注
                    {% if user.id == g.user.id %}
                        <a href="{{ url_for('edit') }}">修改资料</a>
                    {% elif not g.user.is_following(user) %}
                        <a href="{{ url_for('follow', nickname=user.nickname) }}">关注</a>
                    {% else %}
                        <a href="{{ url_for('unfollow', nickname=user.nickname) }}">取消关注</a>
                    {% endif %}
                </p>
            </td>
        </tr>
    </table>

    <hr/>
    {% for post in posts.items %}
        {% include 'post.html' %}
    {% endfor %}

    {% if posts.has_prev %}
        <a href="{{ url_for('user', nickname=user.nickname, page=posts.prev_num) }}">
            << Newer Posts
        </a>
    {% else %}
        << Newer Posts
    {% endif %}
    |
    {% if posts.has_next %}
        <a href="{{ url_for('user', nickname=user.nickname, page=posts.next_num) }}">
            Older Posts >>
        </a>
    {% else %}
        Older Posts >>
    {% endif %}

{% endblock %}